//
//  CQPopupButtonFactory.m
//  AppCommonUICollect
//
//  Created by ciyouzen on 2018/7/3.
//  Copyright © 2018年 dvlproad. All rights reserved.
//

#import "CQPopupButtonFactory.h"
#import <CJBaseUIKit/UIColor+CJHex.h>
#import <CJBaseUIKit/UIButton+CJMoreProperty.h>
#import <Masonry/Masonry.h>
#import "UIImage+CQPopupSuperKitBundle.h"

@implementation CQPopupButtonFactory

/// "关闭"图片按钮
+ (UIView *)closeImageButtonWithCloseHandle:(void(^)(void))closeHandle
{
    UIImage *closeImage = [UIImage imageNamed:@"CQPopupSuperKit.bundle/closePopup"];
    NSAssert(closeImage, @"关闭图片不能为空");
    
    UIButton *closeButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [closeButton setBackgroundImage:closeImage forState:UIControlStateNormal];
    //[closeButton addTarget:self action:@selector(__closeButtonAction) forControlEvents:UIControlEventTouchUpInside];
    closeButton.cjTouchUpInsideBlock = ^(UIButton *button) {
        !closeHandle ?: closeHandle();
    };
    
    return closeButton;
}

//+ (UIView *)iKnowButtonWithOKButtonTitle:(NSString *)okButtonTitle
//                                okHandle:(void(^)(void))okHandle
//{
//    
//}

/// "我知道了"图片按钮
+ (UIView *)iKnowImageButtonWithOKHandle:(void(^)(void))okHandle
{
    UIImage *confirmImage = [UIImage cqPopupSuperKitBundle_imageNamed:@"IKnowDescriptions.png"];
    //UIImage *confirmImage = [UIImage imageNamed:@"IKnowDescriptions.png"]
    
    UIButton *confirmButton = [UIButton buttonWithType:UIButtonTypeCustom];
    confirmButton.backgroundColor = [UIColor whiteColor];
    confirmButton.layer.masksToBounds = YES;
    confirmButton.layer.cornerRadius = 6;
    [confirmButton setBackgroundImage:confirmImage forState:UIControlStateNormal];
    //[confirmButton setTitle:NSLocalizedString(@"我知道了", nil) forState:UIControlStateNormal];
    //[confirmButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    //[confirmButton addTarget:self action:@selector(__confirmButtonAction) forControlEvents:UIControlEventTouchUpInside];
    confirmButton.cjTouchUpInsideBlock = ^(UIButton *button) {
        !okHandle ?: okHandle();
    };
    
    return confirmButton;
}

/*
 *  "Cancel" + "OK" 的 组合按钮
 *
 *  @param cancelButtonTitle    取消文案
 *  @param okButtonTitle        确认文案
 *  @param cancelHandle         取消事件
 *  @param okHandle             确认时间
 */
+ (UIView *)twoButtonsWithCancelButtonTitle:(NSString *)cancelButtonTitle
                              okButtonTitle:(NSString *)okButtonTitle
                               cancelHandle:(void(^)(void))cancelHandle
                                   okHandle:(void(^)(void))okHandle
{
    UIView *buttonsView = [[UIView alloc] init];
    
    // 关闭按钮
    UIButton *cancelButton = [UIButton buttonWithType:UIButtonTypeCustom];
    cancelButton.backgroundColor = CJColorFromHexStringAndAlpha(@"#EEEEEF", 1.0);
    cancelButton.layer.cornerRadius = 25;
    [cancelButton.titleLabel setFont:[UIFont fontWithName:@"PingFangSC-Semibold" size:16]];
    [cancelButton setTitle:cancelButtonTitle forState:UIControlStateNormal];
    [cancelButton setTitleColor:CJColorFromHexStringAndAlpha(@"#0C101B", 1.0) forState:UIControlStateNormal];
    //[cancelButton addTarget:self action:@selector(__cancelAction) forControlEvents:UIControlEventTouchUpInside];
    cancelButton.cjTouchUpInsideBlock = ^(UIButton *button) {
        !cancelHandle ?: cancelHandle();
    };
    [buttonsView addSubview:cancelButton];
    
    UIButton *okButton = [UIButton buttonWithType:UIButtonTypeCustom];
    okButton.backgroundColor = CJColorFromHexStringAndAlpha(@"#0C101B", 1.0);
    okButton.layer.cornerRadius = 25;
    [okButton.titleLabel setFont:[UIFont fontWithName:@"PingFangSC-Semibold" size:16]];
    [okButton setTitle:okButtonTitle forState:UIControlStateNormal];
    [okButton setTitleColor:CJColorFromHexStringAndAlpha(@"#FFFFFF", 1.0) forState:UIControlStateNormal];
    //[okButton addTarget:self action:@selector(__okAction) forControlEvents:UIControlEventTouchUpInside];
    okButton.cjTouchUpInsideBlock = ^(UIButton *button) {
        !okHandle ?: okHandle();
    };
    [buttonsView addSubview:okButton];
    
    NSArray<UIButton *> *bottomButtons = @[cancelButton, okButton];
    [bottomButtons mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.bottom.mas_equalTo(buttonsView);
    }];
    [bottomButtons mas_distributeViewsAlongAxis:MASAxisTypeHorizontal withFixedSpacing:15 leadSpacing:32 tailSpacing:32];
    
    return buttonsView;
}


@end
